package com.naiterui.ehp.bs.wechat.param.custom;

import org.apache.commons.lang3.StringUtils;

import com.naiterui.ehp.bs.wechat.constants.WeChatConstant;
import com.naiterui.ehp.bs.wechat.protocol.msg.custom.CustomMsg;
import com.naiterui.ehp.bs.wechat.protocol.msg.custom.CustomVideo;

import lombok.Data;

/**
 * 视频消息
 * @author zhoupeipei
 * @date 2019-07-05 15:14
 * @since 1.0.0
 */
@Data
public class VideoMsgParam extends BaseCustomParam {
    private static final long serialVersionUID = -6331631977480105209L;
    /**
     * 多媒体资源标识
     */
    private String mediaId;
    /**
     * 缩略图资源标识
     */
    private String thumbMediaId;
    /**
     * 视频标题
     */
    private String title;
    /**
     * 视频描述
     */
    private String description;

    /**
     * 参数构造器
     *
     * @param openId  用户openId
     * @param mediaId 视频文件在微信服务器上的id
     *              <p>【临时素材】通过IMediaApiService.uploadTempMedia上传获得</p>
     *              <p>【永久素材】通过IMediaApiService.uploadMedia上传所得</p>
     * @param thumbMediaId  视频缩略图在微信服务器上的id
     *                  <p>【临时素材】通过IMediaApiService.uploadTempMedia上传获得</p>
     *                  <p>【永久素材】通过IMediaApiService.uploadMedia上传所得</p>
     */
    public VideoMsgParam(String openId, String mediaId,String thumbMediaId) {
        super.setOpenId(openId);
        super.setMsgType(WeChatConstant.KefuMsgType.VIDEO);
        this.mediaId = mediaId;
        this.thumbMediaId = thumbMediaId;
    }

    @Override
    public CustomMsg getCustomProtocol() {
        if (super.validate() && StringUtils.isNotBlank(mediaId)&&StringUtils.isNotEmpty(thumbMediaId)) {
            CustomVideo customVideo = new CustomVideo(mediaId,thumbMediaId);
            return new CustomMsg(getOpenId(), customVideo, getMsgType());
        }
        return null;
    }
}
